﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Bridge.UI.Utilities;

namespace Pathfinder.Base.UI
{
    /// <summary>
    /// View for a UIEnum.
    /// </summary>
    /// <typeparam name="T">Enum that this view represents. Must be a UIEnum.</typeparam>
    public class UIEnumView<T>
    {
        /// <summary>
        /// Default constructor for UIEnumView.
        /// </summary>
        /// <param name="value">Value of the enum.</param>
        /// <exception cref="ArgumentException">Thrown if value is not an enum.</exception>
        public UIEnumView(T value)
        {
            if (!(value is Enum)) throw new ArgumentException("value is not an Enum!", "value");

            Value = value;
        }

        /// <summary>
        /// Value of the UIEnum.
        /// </summary>
        public T Value { get; private set; }

        /// <summary>
        /// Converts this UIEnumView to a string.
        /// </summary>
        /// <returns>String representation of the UIEnum.</returns>
        public override string ToString()
        {
            if (!(Value is Enum)) return "UNKNOWN - BAD TYPE";

            Enum enumValue = Value as Enum;
            UIDisplayAttribute attribute = enumValue.GetUIDisplayAttribute();
            if (attribute != null)
            {
                return string.IsNullOrEmpty(attribute.DisplayName) ? Value.ToString() : attribute.DisplayName;
            }
            return Value.ToString();
        }
    }
}
